package com.alibaba.citrus.ots.platform.enhance.functions.diff.activity.router;

import com.alibaba.citrus.ots.common.util.SpringContextUtil;
import com.alibaba.citrus.ots.platform.enhance.facade.service.diff.common.DiffCheckRequest;
import com.alibaba.citrus.ots.platform.enhance.functions.diff.common.constant.DiffStrategyRouteDict;
import com.alibaba.citrus.ots.platform.enhance.functions.diff.common.constant.SalesOrderDiffStandardFieldDict;
import com.alibaba.citrus.ots.platform.enhance.functions.diff.common.router.DiffCheckProcessor;
import com.alibaba.citrus.ots.platform.enhance.functions.diff.common.template.OneDiffOneTemplate;
import com.alibaba.citrus.ots.platform.enhance.repository.model.diff.common.FieldLineDTO;
import com.alibaba.cz.base.tool.log.Log;
import com.alibaba.lattice2.epoch.sdk.model.Result;
import com.epoch.app.bcots.service.BaseDataService;
import com.epoch.app.bcots.service.UnifiedInventoryService;
import com.epoch.app.otsb2btradecenter.enums.OrderStatus;
import com.epoch.app.otspricecenter.propertyprocess.service.PropertyProcessService;
import com.ql.util.express.ExpressRunner;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Map;
import java.util.Objects;

/**
 * @author: hanguo
 * @create: 2022/01/25
 * @Description sap006主单（基准）和 销售主单 之间的对账
 */
@Component
public class Sap006SDODiffSalesOrderProcessor extends DiffCheckProcessor {

    private Log log = Log.getLogger(Sap006SDODiffSalesOrderProcessor.class);

    @Resource
    private OneDiffOneTemplate oneDiffOneTemplate;


    @Resource
    private PropertyProcessService propertyProcessService;


    @Resource
    private BaseDataService baseDataService;

    @Resource
    private UnifiedInventoryService unifiedInventoryService;

    @Override
    public String obtainStrategyRoute() {
        return DiffStrategyRouteDict.SAP006SDO_DIFF_SALES_ORDER.getStrategyCode();
    }

    @Override
    public Result<String> diff(DiffCheckRequest diffCheckRequest) {

        Map<String, FieldLineDTO> diffDataMap = diffCheckRequest.getDiffDataMap();
        FieldLineDTO successDTO = diffDataMap.get(SalesOrderDiffStandardFieldDict.SAP_006_SUCCESS.getFieldCode());
        if (Objects.nonNull(successDTO) && StringUtils.isNotBlank(successDTO.getFieldValue())) {
            String successValue = successDTO.getFieldValue();
            //成功
            if (OrderStatus.BEFORE_DELIVERY.getCode().toString().equals(successValue)
                    || OrderStatus.WAIT_HANDLE.getCode().toString().equals(successValue)
                    || OrderStatus.WAIT_RECEIVING.getCode().toString().equals(successValue)
            ) {
                successDTO = FieldLineDTO.of("status", SalesOrderDiffStandardFieldDict.SAP_006_SUCCESS.getFieldCode(), "true");
                diffDataMap.put(SalesOrderDiffStandardFieldDict.SAP_006_SUCCESS.getFieldCode(), successDTO);
            }

            //失败
            if (OrderStatus.STAY_PUSH.getCode().equals(successValue)) {
                successDTO = FieldLineDTO.of("status", SalesOrderDiffStandardFieldDict.SAP_006_SUCCESS.getFieldCode(), "false");
                diffDataMap.put(SalesOrderDiffStandardFieldDict.SAP_006_SUCCESS.getFieldCode(), successDTO);
            }
        }


        return super.diff(diffCheckRequest, oneDiffOneTemplate);
    }

}
